package www.dashu.com.dao;

import www.dashu.com.dao.base.BaseDao;
import www.dashu.com.domain.SysRolePerms;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface SysRolePermsDao extends BaseDao<SysRolePerms,Long> {

    @Query(value = "select o from SysRolePerms o where o.id =:id")
    List<SysRolePerms> getSysRolePermsById(@Param("id") Long id);

    @Modifying
    @Query(value = "delete from SysRolePerms o where o.rId = :roleId")
    void deleteSysRolePermsByRoleId(@Param("roleId") Long roleId);

    @Modifying
    @Query(value = "delete from SysRolePerms o where o.pId = :permId")
    void deleteSysRolePermsByPermId(@Param("permId") Long permId);

    @Query(value = "select o.p_id from sys_role_perms o where o.r_id in (:roleIds)", nativeQuery = true)
    List<Long> findSysRolePermsByRoleIds(@Param("roleIds") List<String> roleIds);

}